package com.hzdesk.media.koreabatchmatvector.dao;

import android.content.Context;
import android.util.Log;
import android.util.Xml;

import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBean;
import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBeanDao;
import com.hzdesk.media.koreabatchmatvector.bean.XmlUserBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/4.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class MouseUserDevicesinfoDaoUtils {

    private static final String TAG = MouseUserDevicesinfoDaoUtils.class.getSimpleName();
    private DaoManager daoManager;


    public MouseUserDevicesinfoDaoUtils(Context context) {
        daoManager = DaoManager.getInstance();
        daoManager.init(context);
    }
    /**
     * 插入数据
     *
     * */
    public boolean insertMouseUserDevicesinfo(MouseUserDevicesinfoBean bean){
        boolean flag = false;
        MouseUserDevicesinfoBeanDao dao = daoManager.getDaoSession().getMouseUserDevicesinfoBeanDao();
        try {
            flag = dao.insertOrReplace(bean)== -1? false:true;
        } catch (Exception e) {

        }
        return flag;
    }

    /**
     * @desc 清空数据
     * */

    public void clear(){
        MouseUserDevicesinfoBeanDao dao = daoManager.getDaoSession().getMouseUserDevicesinfoBeanDao();
        try {
            dao.deleteAll();
        } catch (Exception e) {

        }
    }
    /**
     * @desc 查询数据
     * */
    public List<MouseUserDevicesinfoBean> queryAll(){
        MouseUserDevicesinfoBeanDao dao = daoManager.getDaoSession().getMouseUserDevicesinfoBeanDao();
        List<MouseUserDevicesinfoBean> bean = null;
        try {
            bean = dao.loadAll();
        } catch (Exception e) {}
        return bean;
    }

    /**
     * 查询用户基本信息
     * @return
     */
    public List<XmlUserBean> queryUserInfo(){
        List<MouseUserDevicesinfoBean> list =queryAll();
        List<XmlUserBean> mList=new ArrayList<>();
        for (MouseUserDevicesinfoBean bean:list){
            mList.add(new XmlUserBean(bean.getName(),bean.getMouseNum(),1));
        }
        return mList;
    }



    /**
     * @desc 更新数据
     * */
    public boolean update(MouseUserDevicesinfoBean bean){
        boolean flag = false;
      //  Log.e(TAG,"update1111=======");
        try {
            MouseUserDevicesinfoBeanDao dao = daoManager.getDaoSession().getMouseUserDevicesinfoBeanDao();
            dao.update(bean);
           // Log.e(TAG,"update222=======");
            flag = true;
        } catch (Exception e) {}
        return flag;
    }


}
